package com.example.dagger.views;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.example.dagger.R;
import com.example.dagger.base.BaseActivity;
import com.example.dagger.component.DaggerAllComponent;
import com.example.dagger.database.DBHelper;
import com.example.dagger.entity.Student;
import com.example.dagger.module.DBModule;
import com.example.dagger.module.SpUtilsModule;
import com.example.dagger.module.StudentModule;
import com.example.dagger.utils.SpUtils;

import java.util.stream.DoubleStream;

import jakarta.inject.Inject;

public class MainActivity extends BaseActivity implements View.OnClickListener {

    private TextView mText;

    @Inject
    public Student mStudent1;

    @Inject
    public DBHelper mDBHelper;

    @Inject
    public SpUtils mSpUtils;

    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    public void init() {
        mText = findViewById(R.id.text);
        mText.setOnClickListener(this);

        DaggerAllComponent
                .builder()
                .studentModule(new StudentModule())
                .dBModule(new DBModule(this))
                .spUtilsModule(new SpUtilsModule(this))
                .build()
                .injectMainActivity(this);

        mStudent1.setStudent_code("22");
        mStudent1.setStudent_id(1);
        mStudent1.setStudent_name("Jim");
        mStudent1.setUsername("abcdef");
        mStudent1.setPassword("123456");
        mStudent1.setClass_name("2024");
        mDBHelper.insertStudent(mStudent1);

        // 添加课程
        mDBHelper.insertCourse("英语", "MATH101", "李老师");

        // 存入数据
        mSpUtils.putString("key", "value");
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(MainActivity.this, InfoActivity.class);
        startActivity(intent);
    }
}
